### Arbeitsverzeichnis festlegen
setwd("/Volumes/HDextern/Forschung/Habil/daten")
getwd()

## Datensatz einlesen
results <- read.csv("results.csv", header=TRUE, colClasses=c(rep("character",2),rep("numeric",23)), na.strings = "na")

### Zeiträume

periodQ  <- c("1Q1", "1Q2", "1Q3", "1Q4", "2Q1", "2Q2", "2Q3", "2Q4", "3Q1", "3Q2", "3Q3", "3Q4", "4Q1", "4Q2", "4Q3", "4Q4")
periodP  <- c("P1", "P2", "P3")

### Datensatz in Quartale, Perioden aufteilen
Q <- subset (results, subset = results$Date %in% periodQ)
P  <- subset (results, subset = results$Date %in% periodP)

### Monate und Perioden in einem Datensatz zusammenführen
QP <- rbind(Q,P)


### Datensatz in Akteure aufteilen - QP
Armitage  <- subset (QP, QP$Actor=="Ar")
Bush  <- subset (QP, QP$Actor=="Bu")
Cheney  <- subset (QP, QP$Actor=="Ch")
Powell  <- subset (QP, QP$Actor=="Po")
Rice  <- subset (QP, QP$Actor=="Ri")
Rumsfeld  <- subset (QP, QP$Actor=="Ru")
Tenet  <- subset (QP, QP$Actor=="Te")
Wolfowitz  <- subset (QP, QP$Actor=="Wo")

### Datensatz in Akteure aufteilen - Q
QArmitage  <- subset (Q, Q$Actor=="Ar")
QBush  <- subset (Q, Q$Actor=="Bu")
QCheney  <- subset (Q, Q$Actor=="Ch")
QPowell  <- subset (Q, Q$Actor=="Po")
QRice  <- subset (Q, Q$Actor=="Ri")
QRumsfeld  <- subset (Q, Q$Actor=="Ru")
QTenet  <- subset (Q, Q$Actor=="Te")
QWolfowitz  <- subset (Q, Q$Actor=="Wo")

### Datensatz in Akteure aufteilen - P
PArmitage  <- subset (P, P$Actor=="Ar")
PBush  <- subset (P, P$Actor=="Bu")
PCheney  <- subset (P, P$Actor=="Ch")
PPowell  <- subset (P, P$Actor=="Po")
PRice  <- subset (P, P$Actor=="Ri")
PRumsfeld  <- subset (P, P$Actor=="Ru")
PTenet  <- subset (P, P$Actor=="Te")
PWolfowitz  <- subset (P, P$Actor=="Wo")

### z-Werte im Gesamtdokument berechnen und hinzufügen

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)
zQP  <- QP
zQP[c("zP1","zI1","zP4e","zP4a")] <- NA
zQP$zI1  <- (zQP$I1-normGroup[1,2])/normGroup[1,3]
zQP$zP1  <- (zQP$P1-normGroup[2,2])/normGroup[2,3]
zQP$zP4e  <- (zQP$P4-normGroup[3,2])/normGroup[3,3]
zQP$zP4a  <- ((1-zQP$P4)-normGroup[4,2])/normGroup[4,3]
zQP <- zQP[c("Date", "Actor", "P1", "P2", "P3","P4","P5", "I1", "I2","I3","I4a","I4b", "Reward", "Promise", "Appeal", "Oppose", "Threaten", "Punish", "zP1", "zI1", "zP4e", "zP4a")]
write.csv2(zQP, file = "results_total.csv")

### Norming group zur Berechnung der z-scores - Periods

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

PBush[c("zP1","zI1","zP4e","zP4a")] <- NA
PBush$zI1  <- (PBush$I1-normGroup[1,2])/normGroup[1,3]
PBush$zP1  <- (PBush$P1-normGroup[2,2])/normGroup[2,3]
PBush$zP4e  <- (PBush$P4-normGroup[3,2])/normGroup[3,3]
PBush$zP4a  <- ((1-PBush$P4)-normGroup[4,2])/normGroup[4,3]

PCheney[c("zP1","zI1","zP4e","zP4a")] <- NA
PCheney$zI1  <- (PCheney$I1-normGroup[1,2])/normGroup[1,3]
PCheney$zP1  <- (PCheney$P1-normGroup[2,2])/normGroup[2,3]
PCheney$zP4e  <- (PCheney$P4-normGroup[3,2])/normGroup[3,3]
PCheney$zP4a  <- ((1-PCheney$P4)-normGroup[4,2])/normGroup[4,3]

PPowell[c("zP1","zI1","zP4e","zP4a")] <- NA
PPowell$zI1  <- (PPowell$I1-normGroup[1,2])/normGroup[1,3]
PPowell$zP1  <- (PPowell$P1-normGroup[2,2])/normGroup[2,3]
PPowell$zP4e  <- (PPowell$P4-normGroup[3,2])/normGroup[3,3]
PPowell$zP4a  <- ((1-PPowell$P4)-normGroup[4,2])/normGroup[4,3]

PArmitage[c("zP1","zI1","zP4e","zP4a")] <- NA
PArmitage$zI1  <- (PArmitage$I1-normGroup[1,2])/normGroup[1,3]
PArmitage$zP1  <- (PArmitage$P1-normGroup[2,2])/normGroup[2,3]
PArmitage$zP4e  <- (PArmitage$P4-normGroup[3,2])/normGroup[3,3]
PArmitage$zP4a  <- ((1-PArmitage$P4)-normGroup[4,2])/normGroup[4,3]

PRumsfeld[c("zP1","zI1","zP4e","zP4a")] <- NA
PRumsfeld$zI1  <- (PRumsfeld$I1-normGroup[1,2])/normGroup[1,3]
PRumsfeld$zP1  <- (PRumsfeld$P1-normGroup[2,2])/normGroup[2,3]
PRumsfeld$zP4e  <- (PRumsfeld$P4-normGroup[3,2])/normGroup[3,3]
PRumsfeld$zP4a  <- ((1-PRumsfeld$P4)-normGroup[4,2])/normGroup[4,3]

PWolfowitz[c("zP1","zI1","zP4e","zP4a")] <- NA
PWolfowitz$zI1  <- (PWolfowitz$I1-normGroup[1,2])/normGroup[1,3]
PWolfowitz$zP1  <- (PWolfowitz$P1-normGroup[2,2])/normGroup[2,3]
PWolfowitz$zP4e  <- (PWolfowitz$P4-normGroup[3,2])/normGroup[3,3]
PWolfowitz$zP4a  <- ((1-PWolfowitz$P4)-normGroup[4,2])/normGroup[4,3]

PRice[c("zP1","zI1","zP4e","zP4a")] <- NA
PRice$zI1  <- (PRice$I1-normGroup[1,2])/normGroup[1,3]
PRice$zP1  <- (PRice$P1-normGroup[2,2])/normGroup[2,3]
PRice$zP4e  <- (PRice$P4-normGroup[3,2])/normGroup[3,3]
PRice$zP4a  <- ((1-PRice$P4)-normGroup[4,2])/normGroup[4,3]

PTenet[c("zP1","zI1","zP4e","zP4a")] <- NA
PTenet$zI1  <- (PTenet$I1-normGroup[1,2])/normGroup[1,3]
PTenet$zP1  <- (PTenet$P1-normGroup[2,2])/normGroup[2,3]
PTenet$zP4e  <- (PTenet$P4-normGroup[3,2])/normGroup[3,3]
PTenet$zP4a  <- ((1-PTenet$P4)-normGroup[4,2])/normGroup[4,3]


### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


##### Bush - Periods

oca_PBush <- ggplot(PBush) +
  
### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +

### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
      
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)+
  ggsave(file = "oca_PBush.pdf")

pdf("oca_PBush.pdf")
oca_PBush
dev.off()


##### Cheney - Periods

oca_PCheney <- ggplot(PCheney) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PCheney.pdf")
oca_PCheney
dev.off()



##### Powell - Periods

oca_PPowell <- ggplot(PPowell) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PPowell.pdf")
oca_PPowell
dev.off()

##### Armitage - Periods

oca_PArmitage <- ggplot(PArmitage) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PArmitage.pdf")
oca_PArmitage
dev.off()

##### Rumsfeld - Periods

oca_PRumsfeld <- ggplot(PRumsfeld) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PRumsfeld.pdf")
oca_PRumsfeld
dev.off()

##### Wolfowitz - Periods

oca_PWolfowitz <- ggplot(PWolfowitz) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PWolfowitz.pdf")
oca_PWolfowitz
dev.off()

##### Rice - Periods

oca_PRice <- ggplot(PRice) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PRice.pdf")
oca_PRice
dev.off()

##### Tenet - Periods

oca_PTenet <- ggplot(PTenet) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_PTenet.pdf")
oca_PTenet
dev.off()



### Norming group zur Berechnung der z-scores - Quaters

### BUSH

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QBush[c("zP1","zI1","zP4e","zP4a")] <- NA
QBush$zI1  <- (QBush$I1-normGroup[1,2])/normGroup[1,3]
QBush$zP1  <- (QBush$P1-normGroup[2,2])/normGroup[2,3]
QBush$zP4e  <- (QBush$P4-normGroup[3,2])/normGroup[3,3]
QBush$zP4a  <- ((1-QBush$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QBush <- ggplot(QBush) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_QBush.pdf")
oca_QBush
dev.off()


### CHENEY
### Norming group zur Berechnung der z-scores - Quaters - Cheney

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QCheney[c("zP1","zI1","zP4e","zP4a")] <- NA
QCheney$zI1  <- (QCheney$I1-normGroup[1,2])/normGroup[1,3]
QCheney$zP1  <- (QCheney$P1-normGroup[2,2])/normGroup[2,3]
QCheney$zP4e  <- (QCheney$P4-normGroup[3,2])/normGroup[3,3]
QCheney$zP4a  <- ((1-QCheney$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QCheney <- ggplot(QCheney) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_QCheney.pdf")
oca_QCheney
dev.off()

### POWELL
### Norming group zur Berechnung der z-scores - Quaters - Powell

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QPowell[c("zP1","zI1","zP4e","zP4a")] <- NA
QPowell$zI1  <- (QPowell$I1-normGroup[1,2])/normGroup[1,3]
QPowell$zP1  <- (QPowell$P1-normGroup[2,2])/normGroup[2,3]
QPowell$zP4e  <- (QPowell$P4-normGroup[3,2])/normGroup[3,3]
QPowell$zP4a  <- ((1-QPowell$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QPowell <- ggplot(QPowell) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_QPowell.pdf")
oca_QPowell
dev.off()

### Armitage
### Norming group zur Berechnung der z-scores - Quaters - Armitage

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QArmitage[c("zP1","zI1","zP4e","zP4a")] <- NA
QArmitage$zI1  <- (QArmitage$I1-normGroup[1,2])/normGroup[1,3]
QArmitage$zP1  <- (QArmitage$P1-normGroup[2,2])/normGroup[2,3]
QArmitage$zP4e  <- (QArmitage$P4-normGroup[3,2])/normGroup[3,3]
QArmitage$zP4a  <- ((1-QArmitage$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QArmitage <- ggplot(QArmitage) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-3,3)) + 
  scale_y_continuous(limits = c(-3,3)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 3, label = "Type A") +
  annotate("text", x = 1, y = 3, label = "Type C") +
  annotate("text", x = -1, y = -3, label = "Type DEF") +
  annotate("text", x = 1, y = -3, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-3, -2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5, 3), y = -.2, 
           label = c(-3,-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5,+3),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-3,-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5,3), x = -.2, 
           label = c(-3,-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5,+3),
           size = 3)+  ## same for y axis
  
  annotate("text", x=3, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=3, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=3, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.7, label ="P-1(A)", size=3)

pdf("oca_QArmitage.pdf")
oca_QArmitage
dev.off()


### Rumsfeld
### Norming group zur Berechnung der z-scores - Quaters - Rumsfeld

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QRumsfeld[c("zP1","zI1","zP4e","zP4a")] <- NA
QRumsfeld$zI1  <- (QRumsfeld$I1-normGroup[1,2])/normGroup[1,3]
QRumsfeld$zP1  <- (QRumsfeld$P1-normGroup[2,2])/normGroup[2,3]
QRumsfeld$zP4e  <- (QRumsfeld$P4-normGroup[3,2])/normGroup[3,3]
QRumsfeld$zP4a  <- ((1-QRumsfeld$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QRumsfeld <- ggplot(QRumsfeld) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_QRumsfeld.pdf")
oca_QRumsfeld
dev.off()

### WOLFOWITZ
### Norming group zur Berechnung der z-scores - Quaters - Wolfowitz

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QWolfowitz[c("zP1","zI1","zP4e","zP4a")] <- NA
QWolfowitz$zI1  <- (QWolfowitz$I1-normGroup[1,2])/normGroup[1,3]
QWolfowitz$zP1  <- (QWolfowitz$P1-normGroup[2,2])/normGroup[2,3]
QWolfowitz$zP4e  <- (QWolfowitz$P4-normGroup[3,2])/normGroup[3,3]
QWolfowitz$zP4a  <- ((1-QWolfowitz$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QWolfowitz <- ggplot(QWolfowitz) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-2.5,2.5)) + 
  scale_y_continuous(limits = c(-2.5,2.5)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 2.5, label = "Type A") +
  annotate("text", x = 1, y = 2.5, label = "Type C") +
  annotate("text", x = -1, y = -2.5, label = "Type DEF") +
  annotate("text", x = 1, y = -2.5, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), y = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5), x = -.2, 
           label = c(-2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5),
           size = 3)+  ## same for y axis
  
  annotate("text", x=2.5, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=2.5, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.2, y=2.5, label ="I-1(E)", size=3)+
  annotate("text", x=0.2, y=2.3, label ="P-1(A)", size=3)

pdf("oca_QWolfowitz.pdf")
oca_QWolfowitz
dev.off()

### RICE
### Norming group zur Berechnung der z-scores - Quaters - Rice

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QRice[c("zP1","zI1","zP4e","zP4a")] <- NA
QRice$zI1  <- (QRice$I1-normGroup[1,2])/normGroup[1,3]
QRice$zP1  <- (QRice$P1-normGroup[2,2])/normGroup[2,3]
QRice$zP4e  <- (QRice$P4-normGroup[3,2])/normGroup[3,3]
QRice$zP4a  <- ((1-QRice$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QRice <- ggplot(QRice) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-3.2,3.2)) + 
  scale_y_continuous(limits = c(-3.2,3.2)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 3.2, label = "Type A") +
  annotate("text", x = 1, y = 3.2, label = "Type C") +
  annotate("text", x = -1, y = -3.2, label = "Type DEF") +
  annotate("text", x = 1, y = -3.2, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-3, -2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5, 3), y = -.2, 
           label = c(-3, -2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5, +3),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-3, -2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5, 3), x = -.2, 
           label = c(-3, -2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5, +3),
           size = 3)+  ## same for y axis
  
  annotate("text", x=3.0, y=0.3, label ="P-4(E)", size=3)+
  annotate("text", x=3.0, y=0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.3, y=3.0, label ="I-1(E)", size=3)+
  annotate("text", x=0.3, y=2.8, label ="P-1(A)", size=3)

pdf("oca_QRice.pdf")
oca_QRice
dev.off()


### Tenet
### Norming group zur Berechnung der z-scores - Quaters - Tenet

normGroup  <- read.csv("normingGroupOca.csv", header=TRUE)

QTenet[c("zP1","zI1","zP4e","zP4a")] <- NA
QTenet$zI1  <- (QTenet$I1-normGroup[1,2])/normGroup[1,3]
QTenet$zP1  <- (QTenet$P1-normGroup[2,2])/normGroup[2,3]
QTenet$zP4e  <- (QTenet$P4-normGroup[3,2])/normGroup[3,3]
QTenet$zP4a  <- ((1-QTenet$P4)-normGroup[4,2])/normGroup[4,3]

### Credit goes to Zoltan Fazekas, who had the basic idea for this part of the script

require(ggplot2)
require(grid)


oca_QTenet <- ggplot(QTenet) +
  
  ### Ego
  
  geom_point(aes(x = zP4e, y = zI1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#0066FF") + 
  geom_text(aes(x = zP4e, y = zI1, label = Date), size = 3, vjust = 1, colour="#0066FF") + 
  geom_path(aes(x = zP4e, y = zI1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#0066FF") +
  
  ### Alter
  
  geom_point(aes(x = zP4a, y = zP1, label = Date), shape=15, size = 3, alpha = 0.5, colour="#CC0000") + 
  geom_text(aes(x = zP4a, y = zP1, label = Date), size = 3, vjust = 1, colour="#CC0000") + 
  geom_path(aes(x = zP4a, y = zP1, label = Date), arrow = arrow(length = unit(0.45, "cm")), alpha = 0.5, colour="#CC0000") +
  
  theme_bw() +
  xlab("") + ylab("") + 
  geom_hline(yintercept = 0, alpha = 0.5, linetype = "longdash") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = "longdash") + 
  scale_x_continuous(limits = c(-3.2,3.2)) + 
  scale_y_continuous(limits = c(-3.2,3.2)) + 
  theme(panel.border = element_blank(), 
        axis.line = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
  
  annotate("text", x = -1, y = 3, label = "Type A") +
  annotate("text", x = 1, y = 3, label = "Type C") +
  annotate("text", x = -1, y = -3, label = "Type DEF") +
  annotate("text", x = 1, y = -3, label = "Type B") +
  
  annotate("text", x = -1.5, y = 1.5, label = "Appease", colour="grey") +
  annotate("text", x = -0.5, y = 0.75, label = "Reward", colour="grey") +
  annotate("text", x = -1.5, y = -1.5, label = "Bluff", colour="grey") +
  annotate("text", x = -0.5, y = -0.75, label = "Compel", colour="grey") +
  annotate("text", x = 1.5, y = 1.5, label = "Exploit", colour="grey") +
  annotate("text", x = 0.5, y = 0.75, label = "Deter", colour="grey") +
  annotate("text", x = 1.5, y = -1.5, label = "Bully", colour="grey") +
  annotate("text", x = 0.5, y = -0.75, label = "Punish", colour="grey") +
  
  annotate("text", x = c(-3, -2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5, 3), y = -.2, 
           label = c(-3, -2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5, 3),
           size = 3) + ## manual setup for the axis numbering (x)
  annotate("text", y = c(-3, -2.5, -2.0, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5, 3), x = -.2, 
           label = c(-3, -2.5, 2, -1.5, -1, -0.5, +0.5, +1, +1.5, +2, +2.5, 3),
           size = 3)+  ## same for y axis
  
  annotate("text", x=3.2, y= 0.1, label ="P-4(E)", size=3)+
  annotate("text", x=3.2, y= -0.1, label ="P-4(A)", size=3)+
  annotate("text", x=0.3, y=3.2, label ="I-1(E)", size=3)+
  annotate("text", x=0.3, y=3.0, label ="P-1(A)", size=3)

oca_QTenet

#direct.label.ggplot(oca_QTenet,'last.points')

pdf("oca_QTenet.pdf")
oca_QTenet
dev.off()


### Clustering von P1

require(vegan)


P1 <- subset (P, P$Date=="P1")
row.names(P1) <- P1$Actor
P1 <- P1[,c(-1,-2)]

P2 <- subset (P, P$Date=="P2")
row.names(P2) <- P2$Actor
P2 <- P2[,c(-1,-2)]

P3 <- subset (P, P$Date=="P3")
row.names(P3) <- P3$Actor
P3 <- P3[,c(-1,-2)]

d1 <- vegdist(P1, method = "euclidean")
fit1 <- hclust(d1, method="ward") 
plot(fit1, hang=-1)

d1j <- vegdist(P1, method = "jaccard")
fit1j <- hclust(d1j, method="ward") 
plot(fit1j, hang=-1)

d2 <- vegdist(P2, method = "euclidean")
fit2 <- hclust(d2, method="ward") 
plot(fit2, hang=-1)

d2j <- vegdist(P2, method = "jaccard")
fit2j <- hclust(d2j, method="ward") 
plot(fit2j, hang=-1)

d3 <- vegdist(P3, method = "euclidean")
fit3 <- hclust(d3, method="ward") 
plot(fit3, hang=-1)


library(ggdendro)
library(ggplot2)

#convert cluster object to use with ggplot
dendr1 <- dendro_data(fit1, type="rectangle") 

#your own labels are supplied in geom_text() and label=labs
ggplot() + 
  geom_segment(data=segment(dendr1), aes(x=x, y=y, xend=xend, yend=yend)) +
  geom_text(data=label(dendr1), aes(x=x, y=y, label=label, vjust=2), size=4) +
  scale_y_continuous(breaks=c(0.0,0.2,0.4,0.6, 0.8, 1.0,1.2))+
  theme(axis.line.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.x=element_blank(),
        axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        panel.background=element_rect(fill="white"),
        panel.grid=element_blank(),
        legend.position="none")
ggsave(file="dendro_P1.pdf")

#convert cluster object to use with ggplot
dendr2 <- dendro_data(fit2, type="rectangle") 

#your own labels are supplied in geom_text() and label=labs
ggplot() + 
  geom_segment(data=segment(dendr2), aes(x=x, y=y, xend=xend, yend=yend)) +
  geom_text(data=label(dendr2), aes(x=x, y=y, label=label, vjust=2), size=4) +
  scale_y_continuous(breaks=c(0.0,0.2,0.4,0.6, 0.8, 1.0,1.2))+
  theme(axis.line.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.x=element_blank(),
        axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        panel.background=element_rect(fill="white"),
        panel.grid=element_blank(),
        legend.position="none")
ggsave(file="dendro_P2.pdf")

### Spur der Matrix zur Entscheidung, ob "euclidean" oder "jaccard" verwendet werden soll

P1 <- subset (P, P$Date=="P1")
rownames(P1) <- P1[,2]
P1 <- P1[,-c(1:2)]
sum(diag(cov(P1)))

P1.TEWO <- P1[7:8,]
sum(diag(cov(P1.TEWO)))

P1.ARRI <- P1[c(1,5),]
sum(diag(cov(P1.ARRI)))

P1.rest <- P1[c(2,3,4,6),]
sum(diag(cov(P1.rest)))

P1.RUTEWO <- P1[6:8,]
sum(diag(cov(P1.RUTEWO)))

P1.rest2 <- P1[1:5,]
sum(diag(cov(P1.rest2)))

P1.BUCHPO <- P1[2:4,]
sum(diag(cov(P1.BUCHPO)))

sum(diag(cov(P2)))

P2.CHRUWO <- P2[c(2,6,8),]
sum(diag(cov(P2.CHRUWO)))

P2.CHRU <- P2[c(2,6),]
sum(diag(cov(P2.CHRU)))

P2.ARPORI <- P2[c(1,4,5),]
sum(diag(cov(P2.ARPORI)))

P2.TEmi <- P2[-7,]
sum(diag(cov(P2.TEmi)))
